{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Picking manual melt pond depths from ICESat-2 photon data plots\n",
    "(a.k.a. \"Science Humans vs. Science Machines\")\n",
    "\n",
    "## Background\n",
    "We are working on comparing different algorithms that extract the depth of melt ponds on Amery ice shelf from ATL03 photon data (see images below). Because *humans tend to be pretty talented at recognizing patterns in such unstructured data*, we want to investigate how the algorithm estimates compare to where humans would draw the melt pond surface and bed in these data. \n",
    "\n",
    "<p>  \n",
    "<figure>\n",
    "    <img src=\"imgs/amery_ATL03_S2_1.png\" alt=\"Melt pond data Sentinel-2 and ICESat-2\" width=\"800\"/>\n",
    "    <figcaption>Fig.1 - ICESat-2 ATL03 photon elevation data over four melt ponds on Amery Ice Shelf. (Track 0081, 2 Jan 2019, ATL03 Release 003, granule ATL03_20190102184312_00810210_003_01.h5, beam gt2l)</figcaption>\n",
    "</figure>\n",
    "</p>\n",
    "\n",
    "## How YOU can help:\n",
    "If you'd be willing to use about **10 minutes of your time** to help us by connecting some dots on four plots below, we'd greatly appreciated that. It's a good short distraction, and the more estimates we get, the better the data!\n",
    "\n",
    "All you need to do is run the cells in this notebook in sequence, and trace out the surface and lake bed with line segments by clicking on the plots that are generated. The results should look something along the lines of this:\n",
    "<table><tr>\n",
    "<td> <img src=\"imgs/pondPickingExample.png\" alt=\"an example of picked surfaces\" style=\"height: 350px;\"/> </td>\n",
    "<td> <img src=\"imgs/pondPickingCheckExample.png\" alt=\"an example of all picked surfaces when checking the data\" style=\"height: 350px;\"/>  </td>\n",
    "</tr></table>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 1: Tell us who you are :-)\n",
    "Replace `FirstLast` in the first line below with your name, and run this cell. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "YOUR_NAME = 'FirstLast'\n",
    "\n",
    "%matplotlib notebook\n",
    "import numpy as np\n",
    "from pondpicking import PondPicker, getDataDownload"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 2: Pond 1 out of 4\n",
    "Run the cell below. On the plot that appears, pick the surface and the lake bed for pond 1.\n",
    "- Start with tracing out the (flat) water surface. On each mouse click the plot will update to show in blue where you have picked the surface so far. If you want to go back, just press the `'Backspace'` key and you will see your last picked point disappear. If there are multiple water bodies that are disconnected in this transect (small \"islands\"), press `'n'` to start a new line segment that is not connected to the one before. \n",
    "- Press `'2'` on your keyboard to move on to picking the lake bed. This will be plotted in red. You can use the `'Backspace'` and `'n'` keys as before. If you want to return to editing the surface, you can press `'1'` on your keyboard.\n",
    "- Move on to the next cell when you're done.\n",
    "\n",
    "***NOTE:*** *Sometimes there seems to be a second, flat return surface just about half a metre below the pond surface (see below). This is due to oversaturation and dead-time of the sensor. Such second returns are not an actual surface, and should be IGNORED!*\n",
    "<img src=\"imgs/ex3.png\" alt=\"examples of a second return due to sensor oversaturation and dead-time\" width=\"300\"/>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "pond1 = PondPicker(pond=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 3: Pond 2 out of 4\n",
    "Run the cell below. Same as before."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "pond2 = PondPicker(pond=2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 4: Pond 3 out of 4\n",
    "Run the cell below. Same as before."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "pond3 = PondPicker(pond=3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 5: Pond 4 out of 4\n",
    "Run the cell below. Same as before."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "pond4 = PondPicker(pond=4)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 6: Check your data\n",
    "Run the cell below and make sure your picked data looks right on the plot. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "getDataDownload(pond1,pond2,pond3,pond4,YOUR_NAME)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 7: Download the generated data and send it to me\n",
    "Run the cell below. A download link for a csv file will appear. Download the file and email it to parndt(at)ucsd.edu. \n",
    "Thanks :-)\n",
    "\n",
    "*Note: Please actually download the file and send as an attachment. Unfortunately, I will NOT be able to access the file if you just copy-paste the link below...*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from IPython.display import FileLink, FileLinks\n",
    "FileLinks('pickeddata/')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
